#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
开放商户 - 结算规则修改功能使用示例
"""

import os
import sys

# 添加项目根目录到Python路径，确保能够导入jlpay包
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))

from examples.base_example import BaseExample
from jlpay.services.openmerch.change.change_service import ChangeService
from jlpay.model.openmerch.change.settle_rule_modify import SettleRuleModifyRequest


class SettleRuleModifyExample(BaseExample):
    """结算规则修改示例类"""
    
    def __init__(self):
        """初始化示例类"""
        super().__init__("examples.openmerch.change.settle_rule_modify")
        self.change_service = ChangeService(self.config)
    
    def build_settle_rule_modify_request(self):
        """构建结算规则修改请求"""
        request = SettleRuleModifyRequest()
        
        # 设置请求参数 - 根据Java SettleRuleModifyRequest.java中的字段定义
        request.set_org_no("50720711")  # 机构号
        request.set_merch_no("849584358140108")  # 商户号
        request.set_apply_id("b8659ea518d14c99b78b5ad000a0810C")  # 申请单id
        request.set_settle_mode("T1")  # 结算方式
        request.set_day_cut("000000")  # 营业周期，结算日切时间
        request.set_settle_session("070000")  # 结算场次
        request.set_account_change_flag("1")  # 是否允许商户自主变更结算账户，0-否1-是
        request.set_postscript("测试结算规则修改")  # 结算附言
        
        return request
    
    def demo(self):
        """执行结算规则修改示例"""
        self.logger.info("开始执行结算规则修改示例")
        
        # 构建请求
        request = self.build_settle_rule_modify_request()
        
        # 发送请求并处理响应
        self.send_request_and_handle_response(
            self.change_service.modify_settle_rule,
            "结算规则修改",
            request
        )
        
        self.logger.info("结算规则修改示例执行完毕")


if __name__ == "__main__":
    example = SettleRuleModifyExample()
    example.logger.info("=" * 50)
    example.logger.info("===== 结算规则修改示例 开始 =====")
    example.logger.info("=" * 50)
    
    example.demo()
    
    example.logger.info("=" * 50)
    example.logger.info("===== 结算规则修改示例执行完毕 =====")
    example.logger.info("=" * 50) 